package com.huopaolan.yohuoshop.Mvc.View.splash;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.huopaolan.yohuoshop.Mvc.View.GuiDanceActivity;
import com.huopaolan.yohuoshop.Mvc.View.helper.HelperActivity;
import com.huopaolan.yohuoshop.R;

public class ScreenActivity extends AppCompatActivity {
    //是否第一次使用
    private boolean isFirstUse;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_screen);
        final SharedPreferences preferences = getSharedPreferences("isFirstUse", MODE_PRIVATE);
        isFirstUse = preferences.getBoolean("isFirstUse", true);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                enterHomeActivity(preferences);
            }
        }, 2000);
    }

    @Override
    public void onStart() {
        Window window = getWindow();
        window.setStatusBarColor(Color.BLACK);
        super.onStart();
    }

    private void enterHomeActivity(SharedPreferences preferences) {
        if (isFirstUse) {
            startActivity(new Intent(this, GuiDanceActivity.class));
        } else {
            startActivity(new Intent(this, HelperActivity.class));
        }
        finish();
        //实例
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("isFirstUse", false);
        editor.commit();
    }
}
